-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce CLI flag -environment #15422
Conversation
@jsoriano @andrewkroh Some idea for fixing the logging configuration not being ignored when running via systemd. WDYT? |
I think this can be a good approach for the issues raised in #12024 👍 |
We will also need to update docs where we mention the default value for |
13f090c
to
45540f2
Compare
cc @elastic/apm-server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It mostly LGTM, I have added some minor comments. Thanks for addressing this issue!
func init() { | ||
flag.BoolVar(&verbose, "v", false, "Log at INFO level") | ||
flag.BoolVar(&toStderr, "e", false, "Log to stderr and disable syslog/file output") | ||
common.StringArrVarFlag(nil, &debugSelectors, "d", "Enable certain debug selectors") | ||
flag.Var((*environmentVar)(&environment), "environment", "set environment the Beat is run in") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add docs about this new flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is kind of a private flag (a hack) I just introduced as a workaround. I rather wish to remove the flag again in the future. Maybe for 8.0 we have to rethink some logging defaults. e.g. maybe we can detect the environment we are running in, or just log to stdout/stderr by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I think we could consider logging to stdout/stderr by default on 8.0.
func init() { | ||
flag.BoolVar(&verbose, "v", false, "Log at INFO level") | ||
flag.BoolVar(&toStderr, "e", false, "Log to stderr and disable syslog/file output") | ||
common.StringArrVarFlag(nil, &debugSelectors, "d", "Enable certain debug selectors") | ||
flag.Var((*environmentVar)(&environment), "environment", "set environment the Beat is run in") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I think we could consider logging to stdout/stderr by default on 8.0.
d5d0ded
to
0063bbb
Compare
CHANGELOG.next.asciidoc
Outdated
@@ -38,7 +38,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d | |||
|
|||
*Affecting all Beats* | |||
|
|||
TLS or Beats that accept connections over TLS and validate client certificates. {pull}14146[14146] | |||
- TLS or Beats that accept connections over TLS and validate client certificates. {pull}14146[14146] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a line got dropped from the changelog somehow. The full text of this should be:
Fix panics that could result from invalid TLS certificates. This can affect Beats that connect over TLS, or Beats that accept connections over TLS and validate client certificates. {pull}14146[14146]
@@ -910,6 +910,13 @@ messages. | |||
*`-e, --e`*:: | |||
Logs to stderr and disables syslog/file output. | |||
|
|||
*`-environment`*:: | |||
Tell {beatname_uc} the environment it runs into. If no log output is configured |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear up front that this setting relates to logging. Here's my suggested edit based on what I think you're saying here:
For logging purposes, specifies the environment that {beatname_uc} is running in.
This setting is used to select a default log output when no log output is configured.
Supported values are: `systemd`, `container`, `macos_service`, and `windows_service`.
If `systemd` or `container` is specified, {beatname_uc} will log to stdout and stderr
by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will update. Initially I didn't want to this setting to be about logging only. A generic flag like environment
is not really bound to logging. Other subsystems could also be configured differently based on the environment. On the other hand I'd prefer to not have this flag at all...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We can always revisit the description later on if the -environment
option stays around and gets used for other things. :-)
992c4df
to
fe92cd5
Compare
Jenkins, test this. |
1 similar comment
Jenkins, test this. |
Add windows_service, macos_service, and container envionment types. If beats are installed using our scripts the `-environment` flag will always be set. Replace `-e` with `-environment docker` CLI flag in the Dockerfile. Although it's uncommon, users can not overwrite the logging configuration in docker containers as well. The docker(container) environment and systemd environment will default to stdout/stderr logging. All other environments continue to use file rotation as default.
14d3ff4
to
64aff4c
Compare
* Introduce CLI flag -environment Introduce CLI flags -environment to control the default logging settings the Beat should use if no logging is configured. The behavior of -e does not change. By replacing `-e` with `-environment system` in the system unit file we continue to log to stdout/stderr by default, but users are still able to overwrite settings. * Add more environment types Add windows_service, macos_service, and container envionment types. If beats are installed using our scripts the `-environment` flag will always be set. Replace `-e` with `-environment docker` CLI flag in the Dockerfile. Although it's uncommon, users can not overwrite the logging configuration in docker containers as well. The docker(container) environment and systemd environment will default to stdout/stderr logging. All other environments continue to use file rotation as default. (cherry picked from commit 1d3d4d1)
* Introduce CLI flag -environment (#15422) * Introduce CLI flag -environment Introduce CLI flags -environment to control the default logging settings the Beat should use if no logging is configured. The behavior of -e does not change. By replacing `-e` with `-environment system` in the system unit file we continue to log to stdout/stderr by default, but users are still able to overwrite settings. * Add more environment types Add windows_service, macos_service, and container envionment types. If beats are installed using our scripts the `-environment` flag will always be set. Replace `-e` with `-environment docker` CLI flag in the Dockerfile. Although it's uncommon, users can not overwrite the logging configuration in docker containers as well. The docker(container) environment and systemd environment will default to stdout/stderr logging. All other environments continue to use file rotation as default. (cherry picked from commit 1d3d4d1)
Type of change
What does this PR do?
Introduce CLI flags -environment to control the default logging settings
the Beat should use if no logging is configured. The behavior of -e does
not change. By replacing
-e
with-environment system
in the systemunit file we continue to log to stdout/stderr by default, but users are
still able to overwrite settings.
For now (I'm targeting 7.x) I tried to not introduce any breaking changes one way or the other on the config file or CLI level. So the idea is to replace the
-e
flag with the-environment
flag in the systemd unit file. If-environment systemd
is given the default log output is stdout/stderr, while we keep file based logging as default for other environments.Why is it important?
If beats are started via systemd unit files the
-e
CLI flag is added to the list of CLI arguments. This was introduced in #8942. The-e
flag its purpose is to disable the configured logging output and always log to stdout/stderr. By to enforcing the-e
flag the users logging configurations is not honored (for example see the reports in #12024).Checklist
How to test this PR locally
The PR changes how beats are started as Windows Service, macOS service (installed via launchctl), docker container, and via systemd (deb/rpm). For testing Beats must be installed in a few different environment types to check if logs are correctly written to the default target and if log settings can be overwritten.
Running beat locally via command line:
-environment systemd
is given on the command line-environment
flag, without logging configured should create log files as usualRunning a beat via systemd:
/var/log/<beatname>
when settinglogging.to_stderr: false
andlogging.to_file: true
Running beat using old init scripts:
/var/log/<beatname>
by defaultRunning as container:
docker log
is this is really the case.Running on windows
Running as service on macOS
Related issues